package com.frank.controller;

import com.frank.dto.JobRecordDto;
import com.frank.dto.JsonResult;
import com.frank.feign.RecruitFeign;
import com.frank.feign.ResumeFeign;
import com.frank.model.Resume;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deliver")
public class UserRecruitController {

    @Resource
    private ResumeFeign resumeFeign;

    @Resource
    private RecruitFeign recruitFeign;

    @RequestMapping(value = "/createResume", method = RequestMethod.POST)
    JsonResult<?> createResume(@RequestBody Resume resume){
        if (resumeFeign.addResume(resume).getStatus() == 200){
            return new JsonResult<>(200,"获取简历成功");
        }else {
            return new JsonResult<>(500,"获取简历失败");
        }
    }

    @RequestMapping(value = "/getResumeByUserId", method = RequestMethod.GET)
    JsonResult<?> getResumeByUserId(@RequestParam("userId") Integer userId){
        Resume resume = resumeFeign.getByUserId(userId).getData();
        return new JsonResult<>(200,"获取简历成功",resume);
    }

    @RequestMapping(value = "/updateResume", method = RequestMethod.POST)
    JsonResult<?> updateResume(@RequestBody Resume resume){
        if (resumeFeign.updateResume(resume).getStatus() == 200){
            return new JsonResult<>(200,"修改简历成功");
        }else {
            return new JsonResult<>(500,"修改简历失败");
        }
    }

    @RequestMapping(value = "/getJobRecordList", method = RequestMethod.GET)
    JsonResult<?> getJobRecordList(@RequestParam("userId") Integer userId){
        List<JobRecordDto> jobRecordDtoList = recruitFeign.getJobRecordList(userId).getData();
        return new JsonResult<>(200,"获取求职记录列表成功",jobRecordDtoList);
    }

}
